/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.EnableScheduling;

import com.jeesite.common.io.PropertiesUtils;
import com.jeesite.modules.utils.SpringContextUtil;

/**
 * JeeSite Web
 * @author ThinkGem
 * @version 2018-1-8
 */
@EnableScheduling
@SpringBootApplication(scanBasePackages={"com.jeesite.modules", "com.whzc.gameweb.modules"})
public class Application extends SpringBootServletInitializer {
	@Value("${upload.dir}")
	private String uploadDir;
	
	public static void main(String[] args) {
		SpringApplication app = new SpringApplication(Application.class);
		app.setDefaultProperties(PropertiesUtils.getInstance().getProperties());
		ApplicationContext applicationContext = app.run(args);
		
		//添加到spring上下文工具类中，供其他component中随时获取spring上下文对象
		SpringContextUtil.setApplicationContext(applicationContext);
	}
	
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		this.setRegisterErrorPageFilter(false); // 错误页面有容器来处理，而不是SpringBoot
		builder.properties(PropertiesUtils.getInstance().getProperties());
		return builder.sources(Application.class);
	}
	
	/*@Bean
    public ServletRegistrationBean uploadServlet(){
		Map<String, String> params = new HashMap<String, String>();
		params.put("uploadDir", uploadDir);
		ServletRegistrationBean servlet = new ServletRegistrationBean(new UploadServlet(), "/uploadServlet/*");
		servlet.setInitParameters(params);
        return servlet;
    }*/
	
}